//
//  BaseViewController.swift
//  
//
//  Created by hwm on 16/8/28.
//
//

import UIKit

class BaseViewController: UITableViewController {

    
    // 定义属性保存未登录界面
    var visitorView: VisitorView?
    var isLogin: Bool = UserAccount.userLogin()
    
    override func loadView() {
        isLogin ? super.loadView() : setupVisitorView()
    }
    
    // MARK: - 内部控制方法
    /**
     创建未登录界面
     */
    private func setupVisitorView()
    {
        let customView = VisitorView()
        visitorView = customView
        //        customView.backgroundColor = UIColor.redColor()
        view = customView
        
        // 2.设置导航条未登录按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: #selector(BaseViewController.registerBtnWillClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: #selector(BaseViewController.loginBtnWillClick))
    }

    // MARK: 注册
    func registerBtnWillClick() {
        
    }
    
    // MARK: 登录
    func loginBtnWillClick() {
        // 1.弹出登录界面
        let oauth = OAuthViewController()
        let nav = UINavigationController.init()
        nav.addChildViewController(oauth)
        presentViewController(nav, animated: true, completion: nil)
    }
}
